import 'dart:ui';

import 'package:speed_random/app_styles.dart';

class RandComArgs {
  final String title;
  final String list;
  final String cachekey;
  final String settingkeys;

  final Color colorPageText;
  final Color colorAppBarbg;
  final Color colorPagebg;
  final Color colorAppBarText;

  RandComArgs({
    required this.title,
    required this.list,
    required this.cachekey,
    this.colorPageText = AppStyles.colorPageText,
    this.colorAppBarbg = AppStyles.colorAppBarbg,
    this.colorPagebg = AppStyles.colorPagebg,
    this.colorAppBarText = AppStyles.colorAppBarText,
    this.settingkeys ="min,max,num,time,sum,add0,autostop,iscf",
  });

  factory RandComArgs.fromMap(Map<String, dynamic> map) {
    return RandComArgs(
      // 使用空值检查，若值为 null 则使用空字符串作为默认值
      title: map['title'] is String ? map['title'] as String : '',
      list: map['list'] is String ? map['list'] as String : '',
      cachekey: map['cachekey'] is String ? map['cachekey'] as String : '',
      // 颜色类型同样进行空值检查，若为 null 则使用默认颜色
      colorPageText: map['colorPageText'] is Color ? map['colorPageText'] as Color : AppStyles.colorPageText,
      colorAppBarbg: map['colorAppBarbg'] is Color ? map['colorAppBarbg'] as Color : AppStyles.colorAppBarbg,
      colorPagebg: map['colorPagebg'] is Color ? map['colorPagebg'] as Color : AppStyles.colorPagebg,
      colorAppBarText: map['colorAppBarText'] is Color ? map['colorAppBarText'] as Color : AppStyles.colorAppBarText,
      settingkeys: map['settingkeys'] is String ? map['settingkeys'] as String : 'min,max,num,time,sum,add0,autostop,iscf',
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'title': title,
      'list': list,
      'cachekey': cachekey,
      'colorPageText': colorPageText,
      'colorAppBarbg': colorAppBarbg,
      'colorPagebg': colorPagebg,
      'colorAppBarText': colorAppBarText,
      'settingkeys': settingkeys,
    };
  }
}
